/**
 * 
 */
package com.yst.metho.web.application.user.actions;

import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.naming.NamingException;

import nextapp.echo2.app.Button;
import nextapp.echo2.app.event.ActionEvent;
import nextapp.echo2.app.event.ActionListener;

import com.yst.metho.web.application.user.UserListModel;
import com.yst.metho.web.application.user.UserPane;
import com.yst.metho.web.application.utils.Locator;

/**
 * @author perso
 * 
 */
public class ModifyUserBtn extends Button implements ActionListener
{
	private UserListModel mModel;

	private UserPane mView;

	/**
	 * @param model
	 * @param view
	 */
	public ModifyUserBtn(UserListModel model, UserPane view)
	{
		super("Ok");
		mModel = model;
		mView = view;
		addActionListener(this);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see nextapp.echo2.app.event.ActionListener#actionPerformed(nextapp.echo2.app.event.ActionEvent)
	 */
	public void actionPerformed(ActionEvent arg0)
	{
		if (null == mView.getId())
		{

			try
			{
				Locator.getUserView().createUser(mView.getLogin(), mView.getNom(), mView.getPrenom(), mView.getSociete(), mView.getCode(), mView.getMail(), mView.getTjm());
				mModel.refresh();
			}
			catch (NamingException e)
			{
				throw new RuntimeException(e);
			}
			catch (CreateException e)
			{
				throw new RuntimeException(e);
			}
		}
		else
		{
			try
			{
				Locator.getUserView().storeUser(mView.getId(), mView.getNom(), mView.getPrenom(), mView.getSociete(), mView.getCode(), mView.getMail(), mView.getTjm(), mView.getDateFin());
				mModel.refresh();
			}
			catch (NamingException e)
			{
				throw new RuntimeException(e);
			}
			catch (CreateException e)
			{
				throw new RuntimeException(e);
			}
			catch (FinderException e)
			{
				throw new RuntimeException(e);
			}
		}
	}

}
